// SkinBaseView.cpp : implementation file
//

#include "stdafx.h"

#include "SkinBaseView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSkinBaseView

IMPLEMENT_DYNCREATE(CSkinBaseView, CView)

CSkinBaseView::CSkinBaseView()
{
}

CSkinBaseView::~CSkinBaseView()
{
}


BEGIN_MESSAGE_MAP(CSkinBaseView, CView)
	//{{AFX_MSG_MAP(CSkinBaseView)
	ON_WM_CREATE()
	ON_WM_MOVE()
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_SHOWWINDOW()
	ON_WM_TIMER()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSkinBaseView drawing

void CSkinBaseView::OnDraw(CDC* pDC)
{
//	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CSkinBaseView diagnostics

#ifdef _DEBUG
void CSkinBaseView::AssertValid() const
{
	CView::AssertValid();
}

void CSkinBaseView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSkinBaseView message handlers

int CSkinBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	return 0;
}

void CSkinBaseView::OnMove(int x, int y) 
{
	CView::OnMove(x, y);
	
	// TODO: Add your message handler code here
	
}

void CSkinBaseView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CView::OnPaint() for painting messages
}

void CSkinBaseView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	m_SkinManager.ArrangeLayout(this, cx, cy);		
}

void CSkinBaseView::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CView::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	
}

void CSkinBaseView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	CView::OnTimer(nIDEvent);
}

BOOL CSkinBaseView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
	//return CView::OnEraseBkgnd(pDC);
	CRect rc;
	GetClientRect( rc );

	CDC memDC;
	CBitmap Bitmap;	
	
	memDC.CreateCompatibleDC( pDC );
	Bitmap.CreateCompatibleBitmap( pDC, rc.Width(), rc.Height() );
	memDC.SelectObject( &Bitmap );	

	BOOL bResult = PreWM_PAINT(memDC);
	if (bResult)
	{		
		m_SkinManager.Render( &memDC, rc.Width(), rc.Height());
		
		PostWM_PAINT(memDC);

		pDC->BitBlt( 0, 0, rc.Width(), rc.Height(), &memDC, 0, 0, SRCCOPY );				
	}

	if ( Bitmap.GetSafeHandle() )
		Bitmap.DeleteObject();			
	
	return TRUE;
}

void CSkinBaseView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	ModifyStyle( 0, WS_CLIPCHILDREN );

	LoadSkin();	
}
